package com.nine.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.nine.dao.ProductMapper;
import com.nine.entity.Product;
import com.nine.entity.ProductCondition;
import com.nine.service.ProductService;

@Service
@Transactional
public class ProductServiceImpl implements ProductService {
	@Autowired
	private ProductMapper productMapper;
	
	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED) //挂起事务
	public List<Product> getAllProduct() {
		return productMapper.getAllProduct();
	}
	
	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED) //挂起事务
	public List<Product> getAllProduct(int pageSize, int pageCurr) {
		int pageStart = (pageCurr - 1) * pageSize;
		return productMapper.getAllProductByPaging(pageSize, pageStart);
	}

	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED) //挂起事务
	public Integer getProductCount() {
		return productMapper.getProductCount();
	}
	
	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED) //挂起事务
	public Product getProduct(String pid) {
		return productMapper.selectByPrimaryKey(pid);
	}
	
	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED) //挂起事务
	public List<Product> getProductByCondition(ProductCondition condition) {
		condition.setKeyword("%"+condition.getKeyword()+"%");
		return productMapper.getProductByCondition(condition);
	}
	
	@Override
	public Integer addProduct(Product product) {
		return productMapper.insertSelective(product);
	}
	
	@Override
	public Integer deleteProductBypid(String pid) {
		return productMapper.deleteByPrimaryKey(pid);
	}
	
	@Override
	public Integer deleteMoreProduct(String[] pids) {
		return productMapper.deleteMoreProduct(pids);
	}

	@Override
	public Integer updateProduct(Product product) {
		return productMapper.updateByPrimaryKeySelective(product);
	}

}
